import React from "react"
import Cleanup from '../../../../components/lift_components/Cleanup'
import HomeRepair from '../../../../components/lift_components/HomeRepair'
import HouseMoving from '../../../../components/lift_components/HouseMoving'

import { getlifeData }  from '../../../../fetch/lifeService'

export default class LifeWay extends React.Component{
  constructor(){
    super();
    this.state = {
      lifedata:[]
    }
  }
  componentDidMount(){
    const lifeType = this.props.match.params.lifeType
    const result = getlifeData(lifeType)
    result
    .then(data => {
      console.log(data);
      this.setState({
        lifedata:data
      })
    })
  }
  render(){
    const lifeType = this.props.match.params.lifeType
    let setView;
    if(this.state.lifedata.length > 0){
      if(lifeType==='保洁'){
        setView = <Cleanup lifedata={ this.state.lifedata } />
      }else if (lifeType==='家修') {
        setView = <HomeRepair lifedata={ this.state.lifedata }/>
      }else if (lifeType==='搬家') {
        setView = <HouseMoving lifedata={ this.state.lifedata }/>
      }
    }else {
      setView = '数据正在加载中...'
    }

    return(
      <div>
        {setView}
      </div>
    )
  }
}
